﻿namespace PugLib.Extensions.Collections
{
	using System;
	using System.Collections.Generic;
	using System.Linq;

	/// <summary>
	/// http://feeds.feedburner.com/~r/LosTechies/~3/307072628/some-improved-linq-operators.aspx
	/// </summary>
	public static class BetterLinq
	{
		public static IEnumerable<TSource> Distinct<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> comparer)
		{
			return source.Distinct(new DynamicComparer<TSource, TResult>(comparer));
		}

		public static bool Contains<TSource, TResult>(this IEnumerable<TSource> source, TResult value, Func<TSource, TResult> selector)
		{
			foreach (TSource sourceItem in source)
			{
				TResult sourceValue = selector(sourceItem);
				if (sourceValue.Equals(value))
				{
					return true;
				}
			}
			return false;
		}
	}
}